#include <iostream>
#include <cstdio>
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/msg.h>
#include <unistd.h>

int main()
{
    int key = ftok(".", 0x1);
    int msgid = msgget(key, IPC_CREAT | IPC_EXCL | 0666);
    if (msgid == -1)
    {
        perror("msgget");
        return 1;
    }
    std::cout << "message queue create success! " << msgid << std::endl;
    sleep(2);

    msqid_ds q;
    int n = msgctl(msgid, IPC_STAT, &q);
    printf("key->0x%x\n", q.msg_perm.__key);
    sleep(2);

    n = msgctl(msgid, IPC_RMID, NULL);
    if (n == -1)
    {
        perror("msgctl");
        return 1;
    }
    std::cout << "message queue delete success!" << std::endl;
    return 0;
}